package com.zhouzj.task.springcloud.user.controller;

import com.zhouzj.task.springcloud.user.api.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: zhouzhijun
 * @Date: 2021/8/5 10:48
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户注册
     *
     * @param email
     * @param password
     * @param code
     * @return java.lang.Boolean
     * @author zhouzhijun
     * @Date 10:55 2021/8/5
     */
    @PostMapping("/register/{email}/{password}/{code}")
    public Boolean register(@PathVariable("email") String email, @PathVariable("password") String password,
                            @PathVariable("code") String code) {
        return userService.register(email, password, code);
    }

    /**
     * 用户是否注册校验
     *
     * @param email
     * @return java.lang.Boolean
     * @author zhouzhijun
     * @Date 11:00 2021/8/5
     */
    @GetMapping("/registered/{email}")
    public Boolean registerCheck(@PathVariable("email") String email) {
        return userService.registerCheck(email);
    }

    /**
     * 用户登录
     * <p>
     * 验证⽤户名密码合法性，根据⽤户名和密码⽣成token，token存⼊数据库
     *
     * @param email
     * @param password
     * @return java.lang.Boolean
     * @author zhouzhijun
     * @Date 11:02 2021/8/5
     */
    @PostMapping("/login/{email}/{password}")
    public String login(@PathVariable("email") String email, @PathVariable("password") String password) {
        return userService.login(email, password);
    }

    /**
     * 邮箱地址 根据token查询⽤户登录邮箱接⼝
     *
     * @param token
     * @return java.lang.String
     * @author zhouzhijun
     * @Date 11:09 2021/8/5
     */
    @GetMapping("/info/{token}")
    public String info(@PathVariable("token") String token) {
        return userService.info(token);
    }

}
